# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: apis/dm_api_search/search.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import (
    TYPE_CHECKING,
    Dict,
    List,
    Optional,
)

import betterproto
import grpclib
from betterproto.grpc.grpclib_server import ServiceBase


if TYPE_CHECKING:
    import grpclib.server
    from betterproto.grpc.grpclib_client import MetadataLike
    from grpclib.metadata import Deadline


class SearchEntityType(betterproto.Enum):
    UNKNOWN = 0
    FORUM_TOPIC = 1
    FORUM_COMMENT = 2
    GAME = 3
    USER = 4


@dataclass(eq=False, repr=False)
class SearchRequest(betterproto.Message):
    query: str = betterproto.string_field(1)
    search_across: List["SearchEntityType"] = betterproto.enum_field(2)
    skip: int = betterproto.int32_field(3)
    size: int = betterproto.int32_field(4)


@dataclass(eq=False, repr=False)
class SearchResponse(betterproto.Message):
    total: int = betterproto.int32_field(1)
    entities: List["SearchResponseSearchResultEntity"] = betterproto.message_field(2)


@dataclass(eq=False, repr=False)
class SearchResponseSearchResultEntity(betterproto.Message):
    id: str = betterproto.string_field(1)
    type: "SearchEntityType" = betterproto.enum_field(2)
    found_title: str = betterproto.string_field(3)
    original_title: str = betterproto.string_field(4)
    found_text: str = betterproto.string_field(5)


class SearchEngineStub(betterproto.ServiceStub):
    async def search(
        self,
        search_request: "SearchRequest",
        *,
        timeout: Optional[float] = None,
        deadline: Optional["Deadline"] = None,
        metadata: Optional["MetadataLike"] = None,
    ) -> "SearchResponse":
        return await self._unary_unary(
            "/SearchEngine/Search",
            search_request,
            SearchResponse,
            timeout=timeout,
            deadline=deadline,
            metadata=metadata,
        )


class SearchEngineBase(ServiceBase):
    async def search(self, search_request: "SearchRequest") -> "SearchResponse":
        raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)

    async def __rpc_search(
        self, stream: "grpclib.server.Stream[SearchRequest, SearchResponse]",
    ) -> None:
        request = await stream.recv_message()
        response = await self.search(request)
        await stream.send_message(response)

    def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
        return {
            "/SearchEngine/Search": grpclib.const.Handler(
                self.__rpc_search,
                grpclib.const.Cardinality.UNARY_UNARY,
                SearchRequest,
                SearchResponse,
            ),
        }
